package com.ledict.casefiling.init;

import com.ledict.casefiling.entity.SysDict;
import com.ledict.casefiling.entity.SysUser;
import com.ledict.casefiling.service.SysDictService;
import com.ledict.casefiling.service.SysUserService;
import com.ledict.casefiling.utils.RedisUtils;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.lang.reflect.Array;
import java.util.List;

@Component
public class ApplicationRunnerToInitCache implements ApplicationRunner {
    @Autowired
    private SysDictService dictService;
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private SysUserService userService;
    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        System.out.println("************ Application Runner ***********");
        List<SysDict> sysDicts = dictService.selectAll();
        if (null != sysDicts) {
            for (SysDict dict : sysDicts) {
                redisUtils.set("sys:dict:" + dict.getId(), dict);
            }
        }

        SysUser userInfo = userService.gertUserInfo(1);
        if (null != userInfo) {
            System.out.println("userInfo : " + userInfo.getUsername());
        }
    }
}
